<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateAdminTable extends AbstractMigration
{
    public function change(): void
    {
        $table = $this->table('admin', [
            'id' => true,
            'primary_key' => ['id'],
            'comment' => '管理员表',
            'engine' => 'InnoDB',
            'encoding' => 'utf8mb4',
        ]);
        $table->addColumn('user_name', 'string', [
            'limit' => 20,
            'null' => false,
            'default' => '',
            'comment' => '管理员账号',
        ])->addColumn('mobile', 'string', [
            'limit' => 11,
            'null' => false,
            'comment' => '手机号',
        ])->addColumn('email', 'string', [
            'limit' => 50,
            'null' => true,
            'comment' => '邮箱',
        ])->addColumn('password', 'string', [
            'limit' => 255,
            'null' => false,
            'default' => '',
            'comment' => '密码',
        ])->addColumn('avatar', 'string', [
            'limit' => 255,
            'null' => true,
            'comment' => '头像',
        ])->addColumn('status', 'boolean', [
            'null' => false,
            'default' => 1,
            'comment' => '状态:0=禁用,1=启用',
        ])->addColumn('last_login_time', 'timestamp', [
            'null' => true,
            'comment' => '最后登录时间',
        ])->addColumn('last_login_ip', 'string', [
            'limit' => 45,
            'null' => true,
            'comment' => '最后登录IP',
        ])->addColumn('create_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'comment' => '创建时间',
        ])->addColumn('update_time', 'timestamp', [
            'default' => 'CURRENT_TIMESTAMP',
            'update' => 'CURRENT_TIMESTAMP',
            'comment' => '更新时间',
        ])->addIndex(['email'], [
            'name' => 'idx_email',
        ])->addIndex(['user_name'], [
            'name' => 'uk_user_name',
            'unique' => true,
        ])->addIndex(['mobile'], [
            'name' => 'uk_mobile',
            'unique' => true,
        ])->create();
    }
}
